<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>下午茶库存查询列表</title>
    <!--{include file='comm/icheck.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>
<div class="container">

    <div class="comm_content">

            <div  class="search-box">
                <form id="searchForm" class="form-inline" onsubmit="return false;">
                    <div style="position:relative">
                        <span>
                            <span style='width:60px;text-align:right'>配送日期：</span>
                            <input type="text" class="form-control input-sm" style="width: 140px;" value="<!--{$currentDate}-->" name="stock_date" id="stock_date">
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>配送城市：</span>
                            <select id="cityID" name="cityID" class="form-control input-sm" style="width:100px;">
                                <option value="">请选择</option>
                            </select>
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>配送站：</span>
                            <select name="distribution_id" id="distribution_id" class="form-control input-sm" style="width:110px;">
                                <option value="">请选择</option>
                            </select>
                        </span>
                        <span>
                            <span style='width:60px;text-align:right'>商品编码：</span>
                            <input type="text" class="form-control input-sm" style="width:140px" value="" name="product_code" id="product_code">
                        </span>
                         <span>
                            <span style='width:60px;text-align:right'>商品名称：</span>
                            <input type="text" class="form-control input-sm" style="width:140px" value="" name="product_name" id="product_name">
                        </span>
                        <span>
                            <input type="button" class="btn btn-primary" value="查询" onclick="coupon.search();">&nbsp;&nbsp;
                            <input type="button" class="btn btn-warning btn-sm" value="重置" onclick="coupon.cz();">&nbsp;&nbsp;
                        </span>
                    </div>
                </form>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">


    $('#stock_date').datepicker();

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/production/stockSearch.ajax?operFlg=1&stock_date="+$("#stock_date").val(),
        dataType: "json",
        colModel : [
            {display: "操作", width : 150, align: 'center'},
            {display: "库存编号", width : 150, align: 'center'},
            {display: "配送日期", width : 150, align: 'center'},
            {display: "配送站", width : 150, align : 'center' },
            {display: "商品编码", width : 200, align: 'center'},
            {display: "商品名称", width : 200, align: 'center'},
            {display: "申请数量", width : 200, align: 'center'},
            {display: "实际数量", width : 200, align: 'center'}
        ],
       /* buttons : [
            {name: "修改商品库存", bclass: "add", onpress : "coupon.add"},
            {separator: true}

        ],*/
        sortname: "stock_id",
        sortorder: "",
        usepager: true,
        rp: 10,
        useRp: true
    });

    var coupon = {

        //查询
        search : function (){
            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        cz : function(){
            $("#cityID").val('');
            $('#distribution_id').val('');
            $('#product_code').val('');
            $('#product_name').val('');
            $("#stock_date").val('<!--{$currentDate}-->');

            var dt = $("#searchForm").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },
        modStock : function(stock_id){
            E.open("/quanliadmin/app/production/stockSearch.pscript?operFlg=2&stock_id="+stock_id, "" , {height: 500,width:800, top: 100, left: 300});
        },
        stockDetail : function(stock_id){
            E.open("/quanliadmin/app/production/stockSearch.pscript?operFlg=3&stock_id="+stock_id, "" , {height: 500,width:800, top: 100, left: 300});
        }
    };



    $(window).ready(function() {

        $("#cityID").html("");

        var cityHtml = '<option value="">请选择</option>';

        $.ajax({
            type: "post",
            url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=1",
            dataType: "json",
            data: "",
            success: function( result_obj ) {
                if(result_obj.code == 200){
                    $.each(result_obj.data, function(i,val){
                        cityHtml +='<option value="'+val.id+'">'+val.name+'</option>';
                    });
                    $('#cityID').html(cityHtml);
                }else{
                    E.alert(result_obj.message);
                }
            }
        });

        //点击城市联动获得配送站(联动)
        $(document).on('change', '#cityID', function() {

            $('#distribution_id').html("");

            var cityID = $('#cityID').children('option:selected').val();
            var distributionHtml = '<option value="">请选择</option>';
            E.ajax_post({
                url: "/invokingAjax-comm/bill/distribution.ajax?operFlg=2",
                data: {deliver_cityid: cityID},
                call: function( obj ) {
                    if(obj.code ==200 && obj.data != null){

                        $.each(obj.data, function(i,val){
                            distributionHtml +='<option value="'+val.distribution_id+'">'+val.distribution_name+'</option>';
                        });
                        $('#distribution_id').html(distributionHtml);
                    }else{

                        distributionHtml += '';
                        $('#distribution_id').html(distributionHtml);
                    }
                }
            });
        });
    });

</script>

</body>
</html>